<?php
class CategoryModel extends Model{
	public $table='category';
	public function getAll(){
		return $this->select();
	}
	//添加栏目
	public function addCate($data){
		if(empty($data['catname'])){
			$this->error='栏目名称不能为空';
			return false;
		}
		return $this->insert($data);
	}
	//编辑栏目
	public function editCate($data){
		if(empty($data['catname'])){
			$this->error='栏目名称不能为空';
			return false;
		}
		$res=$this->where("cid<>{$_GET['cid']} and catname='{$data['catname']}'")->find();
		if(!empty($res)){
			$this->error='栏目名称不能重复';
			return false;
		}
		return $this->where("cid={$_GET['cid']}")->update($data);
	}
	//删除栏目
	public function delCate(){
		$sql="delete * from blog b join category c on c.cid=b.bid where cid={$_GET['cid']}";
		return $this->exe($sql);
	}
}
?>